package com.gjy.concurrency.juc;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-02-20 15:09:50
 */
public class QueueTest {

    private static final BlockingQueue<Integer> BQ = new ArrayBlockingQueue<>(3);

    @Test
    public void test4() {

    }

    @Test
    public void test3() throws InterruptedException {
        BQ.put(1);
        BQ.put(1);
        BQ.put(1);
//        BQ.put(1);
        System.out.println("BQ.take() = " + BQ.take());
        System.out.println("BQ.take() = " + BQ.take());
        System.out.println("BQ.take() = " + BQ.take());
        System.out.println("BQ.take() = " + BQ.take());
    }

    @Test
    public void test2() {
        System.out.println("BQ.offer(1) = " + BQ.offer(1));
        System.out.println("BQ.offer(1) = " + BQ.offer(2));
        System.out.println("BQ.offer(1) = " + BQ.offer(3));
        System.out.println("BQ.offer(1) = " + BQ.offer(4));

        System.out.println("BQ.peek() = " + BQ.peek());

        System.out.println("BQ.poll() = " + BQ.poll());
        System.out.println("BQ.poll() = " + BQ.poll());
        System.out.println("BQ.poll() = " + BQ.poll());
        System.out.println("BQ.poll() = " + BQ.poll());
    }

    @Test
    public void test1() {
        BQ.add(1);
        BQ.add(1);
        BQ.add(1);

        BQ.remove();
        BQ.remove();
        BQ.remove();
        System.out.println("BQ = " + BQ);
    }
}
